package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.UserDO;
import com.qk.dto.UserDTO;
import com.qk.entity.User;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @author 上官徵羽
 * @version 1.0
 * @since 2025-10-08 15:31
 */
@Slf4j
@RestController
@SuppressWarnings("all")
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping
    public Result listPage(UserDTO userDTO){
        PageResult<UserDO> pageResult = userService.listPage(userDTO);
        return Result.success(pageResult);
    }
    @LogAnno
    @DeleteMapping("/{ids}")
    public Result deleteByList(@PathVariable List<Integer> ids){
        userService.deleteByList(ids);
        return Result.success();
    }
    @LogAnno
    @PostMapping
    public Result addUser(@RequestBody User user){
        userService.addUser(user);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        User user = userService.getById(id);
        return Result.success(user);
    }
    @LogAnno
    @PutMapping
    public Result updateById(@RequestBody User user){
        userService.updateById(user);
        return Result.success();
    }
    @GetMapping("/list")
    public Result listAll(){
        List<UserDO> list = userService.listAll();
        return Result.success(list);
    }
    @GetMapping("/role/{roleLabel}")
    public Result listByRole(@PathVariable String roleLabel){
        List<User> list = userService.listByRole(roleLabel);
        return Result.success(list);
    }
    @GetMapping("/dept/{deptId}")
    public Result listByDept(@PathVariable Integer deptId){
        List<User> list = userService.listByDept(deptId);
        return Result.success(list);
    }
}



